import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Controls.Material

GridLayout {
    id: form
    columns: 2
    columnSpacing: 20
    rowSpacing: 15
    anchors.margins: 16

    function getStudentData() {
        return {
            id: idField.text,
            name: nameField.text,
            gender: genderGroup.checkedButton.text,
            college: collegeField.text,
            department: deptField.text,
            className: classField.text,
            dormitory: dormField.text,
            hometown: hometownField.text,
            phone: phoneField.text
        }
    }

    function clear() {
        idField.text = ""
        nameField.text = ""
        maleRadio.checked = true
        collegeField.text = ""
        deptField.text = ""
        classField.text = ""
        dormField.text = ""
        hometownField.text = ""
        phoneField.text = ""
    }

    // 表单标题
    Label {
        Layout.columnSpan: 2
        text: "学生信息"
        font.bold: true
        font.pixelSize: 18
        color: Material.primary
        padding: 8
        Layout.alignment: Qt.AlignCenter
    }

    // 学号
    Label {
        text: "学号*:"
        Layout.maximumWidth: 80
        elide: Text.ElideRight
    }
    TextField {
        id: idField
        Layout.fillWidth: true
        placeholderText: "请输入学号"
        Material.accent: Material.primary
        Material.foreground: "white"
        Material.background: "#2a2a4a"
        Material.theme: Material.Dark
        selectByMouse: true
        implicitHeight: 56 // 确保足够高度显示标签动画
    }

    // 姓名
    Label {
        text: "姓名*:"
        Layout.maximumWidth: 80
        elide: Text.ElideRight
    }
    TextField {
        id: nameField
        Layout.fillWidth: true
        placeholderText: "请输入姓名"
        Material.accent: Material.primary
        Material.foreground: "white"
        Material.background: "#2a2a4a"
        Material.theme: Material.Dark
        selectByMouse: true
        implicitHeight: 56
    }

    // 性别
    Label {
        text: "性别:"
        Layout.maximumWidth: 80
        elide: Text.ElideRight
    }
    RowLayout {
        Layout.fillWidth: true

        RadioButton {
            id: maleRadio
            text: "男"
            checked: true
            Material.accent: Material.primary
            Layout.preferredWidth: 80
        }
        RadioButton {
            id: femaleRadio
            text: "女"
            Material.accent: Material.primary
            Layout.preferredWidth: 80
        }
        ButtonGroup {
            id: genderGroup
            buttons: [maleRadio, femaleRadio]
        }
    }

    // 学院
    Label {
        text: "学院:"
        Layout.maximumWidth: 80
        elide: Text.ElideRight
    }
    TextField {
        id: collegeField
        Layout.fillWidth: true
        placeholderText: "请输入学院"
        Material.accent: Material.primary
        Material.foreground: "white"
        Material.background: "#2a2a4a"
        Material.theme: Material.Dark
        selectByMouse: true
        implicitHeight: 56
    }

    // 系
    Label {
        text: "系:"
        Layout.maximumWidth: 80
        elide: Text.ElideRight
    }
    TextField {
        id: deptField
        Layout.fillWidth: true
        placeholderText: "请输入系"
        Material.accent: Material.primary
        Material.foreground: "white"
        Material.background: "#2a2a4a"
        Material.theme: Material.Dark
        selectByMouse: true
        implicitHeight: 56
    }

    // 班级
    Label {
        text: "班级:"
        Layout.maximumWidth: 80
        elide: Text.ElideRight
    }
    TextField {
        id: classField
        Layout.fillWidth: true
        placeholderText: "请输入班级"
        Material.accent: Material.primary
        Material.foreground: "white"
        Material.background: "#2a2a4a"
        Material.theme: Material.Dark
        selectByMouse: true
        implicitHeight: 56
    }

    // 宿舍
    Label {
        text: "宿舍:"
        Layout.maximumWidth: 80
        elide: Text.ElideRight
    }
    TextField {
        id: dormField
        Layout.fillWidth: true
        placeholderText: "请输入宿舍"
        Material.accent: Material.primary
        Material.foreground: "white"
        Material.background: "#2a2a4a"
        Material.theme: Material.Dark
        selectByMouse: true
        implicitHeight: 56
    }

    // 籍贯
    Label {
        text: "籍贯:"
        Layout.maximumWidth: 80
        elide: Text.ElideRight
    }
    TextField {
        id: hometownField
        Layout.fillWidth: true
        placeholderText: "请输入籍贯"
        Material.accent: Material.primary
        Material.foreground: "white"
        Material.background: "#2a2a4a"
        Material.theme: Material.Dark
        selectByMouse: true
        implicitHeight: 56
    }

    // 电话
    Label {
        text: "电话:"
        Layout.maximumWidth: 80
        elide: Text.ElideRight
    }
    TextField {
        id: phoneField
        Layout.fillWidth: true
        placeholderText: "请输入联系电话"
        inputMethodHints: Qt.ImhDialableCharactersOnly
        Material.accent: Material.primary
        Material.foreground: "white"
        Material.background: "#2a2a4a"
        Material.theme: Material.Dark
        selectByMouse: true
        implicitHeight: 56
    }
}